package com.leyou.item.web;


import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    //根据id查询商品分类
        @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> CategoryById(@PathVariable("id") long id){
            return ResponseEntity.ok(new CategoryDTO(categoryService.getById(id)));
        }

        //根据分类id的集合，查询商品分类的集合
        @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> CategoryByIds(@RequestParam("ids") List<Long> ids){
          return ResponseEntity.ok(CategoryDTO.convertEntityList(categoryService.listByIds(ids)));
        }
        //根据父类id查询子类集合
        @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>>CategoryIds(@RequestParam("pid") Long pid){
            return ResponseEntity.ok(CategoryDTO.convertEntityList(categoryService.query().eq("parent_id",pid).list()));
        }

     @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> CategoryIdcons(@RequestParam("id") Long brandId){
        return ResponseEntity.ok(categoryService.queryCategoryByBrandId(brandId));
     }
}
